package org.tis.tools.senior.module.developer.controller;

import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.tis.tools.core.web.controller.BaseController;
import org.tis.tools.model.common.ResultVO;
import org.tis.tools.senior.module.core.web.util.ShiroUtil;
import org.tis.tools.senior.module.developer.controller.request.DeliveryListAndDeliveryAddRequest;
import org.tis.tools.senior.module.developer.controller.request.DeliveryListSelectRequest;
import org.tis.tools.senior.module.developer.controller.request.DeliveryListSuperadditionRequest;
import org.tis.tools.senior.module.developer.entity.SDeliveryList;
import org.tis.tools.senior.module.developer.entity.SSvnAccount;
import org.tis.tools.senior.module.developer.service.ISDeliveryListService;
import org.tmatesoft.svn.core.SVNException;

import javax.validation.constraints.NotBlank;

/**
 * sDeliveryList的Controller类
 * 
 * @author Auto Generate Tools
 * @date 2018/06/20
 */
@RestController
@RequestMapping("/sDeliveryList")
public class SDeliveryListController extends BaseController<SDeliveryList>  {

    @Autowired
    private ISDeliveryListService sDeliveryListService;

    /**
     * 整理提交历史展示
     *
     * @param branchGuid 分支guid
     * @return
     */
    //@OperateLog(type = OperateType.QUERY, desc = "整理清单")
    @ApiOperation(value = "整理提交历史展示", notes = "url传参")
    @GetMapping("/{branchGuid}/history")
    public ResultVO assembleDelivery(@PathVariable @NotBlank(message = "分支guid不能为空") String branchGuid) throws SVNException {
        return ResultVO.success("查询成功",sDeliveryListService.assembleDelivery(branchGuid));
    }

    /**
     *
     * 添加投放申请以及投产代码清单
     * @param request
     * @return
     * @throws Exception
     */
    //@OperateLog(type = OperateType.ADD, desc = "提清单")
    @ApiOperation(value = "提清单", notes = "body传参")
    @PostMapping("/deliveryAndDeliveryList")
    public ResultVO addDelivery(@RequestBody @Validated DeliveryListAndDeliveryAddRequest request) throws Exception {

        SSvnAccount sSvnAccount = ShiroUtil.getUser();
        return ResultVO.success("添加成功",sDeliveryListService.addDeliveryList(request,sSvnAccount.getUserId()));
    }

    /**
     * 追加投放申请
     * @return
     */
    //@OperateLog(type = OperateType.ADD, desc = "追加投放申请")
    @ApiOperation(value = "追加投放申请", notes = "body传参")
    @PostMapping("/superadditionDeliverylist")
    public ResultVO superadditionDeliverylist(@RequestBody @Validated DeliveryListSuperadditionRequest request) throws SVNException {

        return ResultVO.success("添加成功",sDeliveryListService.addToDeliveryList(request));
    }
    /**
     * 根据文件查询工作项
     * @return
     */
    @PostMapping("standardList/compare")
    public ResultVO selectListByFileName(@RequestBody @Validated DeliveryListSelectRequest request )  {
        return ResultVO.success("查询成功",sDeliveryListService.selectListByFileName( request ) );
    }
}

